package com.zb.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjServicePage;
import com.zb.entity.ZjServicePageIcon;
import com.zb.extend.ServicePageExtend;
import com.zb.mapper.ZjServicePageMapper;
import com.zb.service.ZjServicePageIconService;
import com.zb.service.ZjServicePageService;
import com.zb.vo.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 系统服务页面表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2023-10-31
 */
@Service
public class ZjServicePageServiceImpl extends ServiceImpl<ZjServicePageMapper, ZjServicePage> implements ZjServicePageService {
    @Resource
    private ZjServicePageMapper servicePageMapper;
    @Resource
    private ZjServicePageIconService servicePageIconService;


    // 获取服务页面列表
    @Override
    public List<ServicePageExtend> getList(Long custAccId, ServicePageSelectVo selectVo) {
        return servicePageMapper.getList(custAccId, selectVo);
    }

    // 获取服务页面列表总记录数
    @Override
    public long getListCount(Long custAccId, ServicePageSelectVo selectVo) {
        return servicePageMapper.getListCount(custAccId, selectVo);
    }

    // 批量启用或禁用服务页面
    @Override
    public void updateDisableBatchById(List<Long> ids, boolean status) {
        if (CollectionUtil.isEmpty(ids)) {
            return;
        }
        servicePageMapper.updateDisableBatchById(ids, status);
    }

    // 修改服务页面标题与状态
    @Override
    public void udpateServicePageTitle(ServicePageTitleVo pageTitleVo) {
        ZjServicePage page = new ZjServicePage();
        page.setId(pageTitleVo.getId());
        page.setPageTitle(pageTitleVo.getTitle());
        page.setDisabled(pageTitleVo.getStatus());
        this.updateById(page);
    }

    // 修改服务页面二维码信息
    @Override
    @Transactional
    public void updateServicePageQr(Long custAccId, ServicePageQrVo servicePageQrVo) {
        ZjServicePage page = new ZjServicePage();
        BeanUtil.copyProperties(servicePageQrVo, page);
        this.updateById(page);
        servicePageIconService.save(custAccId, page.getId(), servicePageQrVo.getPageIcons(), servicePageQrVo.getDelPageIconIds());
    }
}
